#include <pcap.h>
#include <assert.h>

#include "socket_init.h"
#include "log.h"

int socket_init(u_int16_t port,u_int32_t server_ip,struct sockaddr_in *addr_local)
{
	int s;

	 /*建立socket*/
        s=socket(AF_INET,SOCK_DGRAM,0);

        //next is init the sockaddr_in of server
        //

        /* 填写sockaddr_in*/
        addr_local->sin_family = AF_INET;
        addr_local->sin_port = htons(port);
        addr_local->sin_addr.s_addr = htonl(INADDR_ANY) ;

	int ret = bind(s,(struct sockaddr *)addr_local, sizeof(*addr_local));

        if(ret<0)
	{
		/*将字串返回给client端*/
		perror("socket bind of local addr failed");
		log_error("socket bind of local addr failed");
                return -2;
        }

        return s;
}
